<template>
  <base-layout
    :dialog-title="dialogTitle"
    :dialog-visible="dialogVisible"
    @dialog-close="dialogClose"
    :dialogWidth="dialogWidth"
  >
    <template #searchPanel>
      <search-panel
        :selectPer="'111'"
        :excelPer="'admin'"
        addTitle="新增快速单"
        @search="search"
        :showSearchButton="true"
        :showAddButton="false"
        :showExportButton="true"
        @export="handleDataExport('WorkOrder','工单管理')"
      >
        <job-shop v-model="searchOptions.storeId" placeholder="所属门店" />
        <el-select clearable v-model="searchOptions.status" placeholder="状态">
          <el-option
            v-for="item in types['工单状态']"
            :key="item.index"
            :value="item.value"
            :label="item.text"
          />
        </el-select>
        <el-select clearable v-model="searchOptions.orderType" placeholder="工单类型">
          <el-option
            v-for="item in types['工单类型']"
            :key="item.index"
            :value="item.value"
            :label="item.text"
          />
        </el-select>
        <el-select clearable v-model="searchOptions.project" placeholder="索赔项目">
          <el-option
            v-for="item in types['汽车项目类型']"
            :key="item.index"
            :value="item.value"
            :label="item.text"
          />
        </el-select>
        <el-input
          v-model="searchOptions.likeName"
          clearable
          placeholder="工单编号/客户手机号/客户姓名/车牌"
          style="width: 200px"
        />
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="true"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :width="160"
      >
        <template #action="{ row }">
          <i
            v-if="row.pickCarId"
            class="el-icon-view"
            title="查看接车单"
            style="cursor: pointer"
            @click="view(row)"
          ></i>
          <i title="红冲" 
            class="el-icon-s-order cursor" 
            @click="handleDialog(row, '红冲申请')"
          ></i>
          <i title="退款申请"
            class="cursor" 
            @click="handleDialog(row, '退款申请')"
          >退</i>
        </template>
      </data-table>
    </template>

    <template #dialog>
      <!-- toto:ymc  workOrderType 类型等于  1快速 2洗车 3综合 4报价 5销售 然后再确认所有工单的详情是否都是用这个组件 -->
      <!-- <dialog-view-detail
        :workOrderId="selectRow.id"
        :workOrderType="1"
        @close="dialogCloseEv"
      /> -->
      <dialog-data-form 
        v-if="dialogTitle == '红冲申请'"
        :value="selectedItem" 
        :type="operationType" 
        @operate="handleDataOperate" 
        @close="dialogCloseEv"
      />
      <dialog-refund-form 
        v-if="dialogTitle == '退款申请'"
        :value="selectedItem" 
        :type="operationType" 
        @operate="handleDataOperate" 
        @close="dialogCloseEv"
      />
    </template>
  </base-layout>
</template>
<script>
import { page } from "@/api/after-sale/workOrderManage/orderManage";
import baseMixin from "@/mixins/base";
import DialogViewDetail from "../../view/index.vue";
import DialogDataForm from './components/DialogDataForm.vue'
import DialogRefundForm from './components/DialogRefundForm.vue'
import { JobShop } from "@/components/index";
import { getDict } from "@/utils";
export default {
  components: { JobShop, DialogViewDetail, DialogDataForm, DialogRefundForm },
  mixins: [
    baseMixin({
      findData: page,
      dataName: ["content", "totalRecords"],
      isAdd: false,
      idName: "id",
    }),
  ],
  data() {
    return {
      dialogWidth: "500px",
      dialogVisible: false,
      tableColumnAttributes: [
        { name: "所属门店", value: "storeName", type: "text", width: "150px" },
        { name: "工单编号", value: "code", type: "text", width: "150px" },
        { name: "工单类型", value: "orderType", type: "text" },
        { name: "单据日期", value: "createTime", type: "text", width: "150px" },
        { name: "车牌号", value: "licensePlateNumber", type: "text" },
        { name: "客户姓名", value: "clientName", type: "text", width: "150px" },
        { name: "性别", value: "genderCst", type: "text" },
        { name: "客户联系方式", value: "phone", type: "text" },
        { name: "项目总数", value: "projectNumber", type: "text" },
        { name: "接待人员", value: "receptionName", type: "text", width: "150px" },
        {
          name: "预计交车时间",
          value: "predictDeliveryDate",
          type: "text",
          width: "150px",
        },
        { name: "付款状态", value: "payStatus", type: "text" },
        { name: "状态", value: "status", type: "text" },
        { name: "红冲状态", value: "redWashStatus", type: "text" },
        { name: "退款状态", value: "refundAuditStatus", 
          type: "render",
          render: (row, value) => {
            if (value == 1) {
              return '待审核'
            } else if (value == 2) {
              return '待审核(售后经理)'
            } else if (value == 3) {
              return '已审核(财务审核)'
            } else if (value == 4) {
              return '已拒绝'
            }
            return ``;
          },
        },
        { name: "当前作业项目", value: "currentProjectName", type: "text" },
        { name: "当前作业人员", value: "currentUserName", type: "text" },
        { name: "工单总金额", value: "amount", type: "text" },
        { name: "工单备注", value: "remark", type: "text", width: "150px" },
        { name: "录入时间", value: "createTime", type: "text", width: "150px" },
      ],
      types: {},
      selectedItem: {},
      operationType: null,
    };
  },
  async created() {
    this.types = getDict(["工单状态", "工单类型", "汽车项目类型"]);
  },
  methods: {
    search() {
      this.currentPage = 1;
      this.setTableData();
    },
    dialogCloseEv() {
      this.dialogClose();
      this.setTableData();
    },
    view(row) {
      this.$router.push({
        path: "/workOrderManage/viewPickUpOrder",
        query: {
          id: row.pickCarId,
          type: "view",
        },
      });
    },
    handleDialog(row, type) {
      this.selectedItem = row;
      this.operationType = type;
      this.handleDataInsert(type);
    }
  },
};
</script>
<style lang="scss" scoped>
.marginLeft {
  margin-left: 10px;
}
.cursor {
  margin-left: 15px;
  cursor: pointer
}
/deep/ .el-dialog{
  min-width: 500px !important;
}
</style>
